package com.igeek.base.ch0715.Demo1;import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


/**
 * @Description TODO
 * @Author chenmin
 * @Date 2024/7/15 19:53
 */
public class Text {
    public static void main(String[] args) {
        List<User> users = new ArrayList<>();
        users.add(new User("user1", "111"));
        users.add(new User("user2", "222"));
        users.add(new User("user3", "333"));
        users.add(new User("user4", "444"));
        users.add(new User("user5", "555"));

        Scanner input = new Scanner(System.in);
        int attempt = 3;

        while (attempt > 0) {
            System.out.print("请输入用户名：");
            String username = input.next();
            System.out.print("请输入密码：");
            String password = input.next();

            User inputUser = new User(username, password);
            if (users.contains(inputUser)) {
                System.out.println("登录成功！");
                break;
            } else {
                System.out.println("用户名或密码错误，登录失败。");
                attempt--;
                if (attempt > 0) {
                    System.out.println("您还有 " + attempt + " 次尝试机会。");
                }
            }
        }

        if (attempt==0) {
            System.out.println("三次输入机会已用完，登录失败。");
        }

    }
}
